package gcontent.utils;

import java.net.*;

public class IP {
	public static InetAddress NormalizeAddress(String address) throws UnknownHostException
	{
		if (Character.isDigit(address.charAt(0)))
        {
            byte[] b = new byte[4];
            String[] bytes = address.split("[.]");
            for (int i = 0; i < bytes.length; i++)
                b[i] = new Integer(bytes[i]).byteValue();
         
            return InetAddress.getByAddress(b);
        }
        else
        {
            return InetAddress.getByName(address);
        }	
	}
	
	public static String getIpAddress(String host) throws UnknownHostException
	{
		if (Character.isDigit(host.charAt(0)))
        {
            byte[] b = new byte[4];
            String[] bytes = host.split("[.]");
            for (int i = 0; i < bytes.length; i++)
                b[i] = new Integer(bytes[i]).byteValue();
         
            return new String(b);
        }
        else
        {
        	String ip = InetAddress.getByName(gcontent.utils.URLUtils.splitProtocol(host)).getHostAddress();
        	return ip;
        }	
	}
}
